package com.pw.manage.education.service.impl;

import java.util.List;

import com.pw.domain.EmployeesBaseInfo;
import com.pw.manage.education.domain.vo.EmployeesEducationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.pw.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.pw.manage.education.domain.EmployeesEducation;
import com.pw.manage.education.mapper.EmployeesEducationMapper;
import com.pw.manage.education.service.IEmployeesEducationService;

/**
 * 员工基本信息Service业务层处理
 *
 * @author lye
 * @date 2024-12-28
 */
@Service
public class EmployeesEducationServiceImpl implements IEmployeesEducationService
{
    @Autowired
    private EmployeesEducationMapper employeesBaseInfoMapper;

    /**
     * 查询员工基本信息
     *
     * @param id 员工基本信息主键
     * @return 员工基本信息
     */
    @Override
    public EmployeesBaseInfo selectEmployeesBaseInfoById(Long id)
    {
        return employeesBaseInfoMapper.selectEmployeesBaseInfoById(id);
    }

    /**
     * 查询员工基本信息列表
     *
     * @param employeesBaseInfo 员工基本信息
     * @return 员工基本信息
     */
    @Override
    public List<EmployeesBaseInfo> selectEmployeesBaseInfoList(EmployeesBaseInfo employeesBaseInfo)
    {
        return employeesBaseInfoMapper.selectEmployeesBaseInfoList(employeesBaseInfo);
    }

    /**
     * 新增员工基本信息
     *
     * @param employeesBaseInfo 员工基本信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertEmployeesBaseInfo(EmployeesBaseInfo employeesBaseInfo)
    {
        int rows = employeesBaseInfoMapper.insertEmployeesBaseInfo(employeesBaseInfo);
        insertEmployeesEducation(employeesBaseInfo);
        return rows;
    }

    /**
     * 修改员工基本信息
     *
     * @param employeesBaseInfo 员工基本信息
     * @return 结果
     */
    @Transactional
    @Override
    public int updateEmployeesBaseInfo(EmployeesBaseInfo employeesBaseInfo)
    {
        employeesBaseInfoMapper.deleteEmployeesEducationByEmployeeId(employeesBaseInfo.getId());
        insertEmployeesEducation(employeesBaseInfo);
        return employeesBaseInfoMapper.updateEmployeesBaseInfo(employeesBaseInfo);
    }

    /**
     * 批量删除员工基本信息
     *
     * @param ids 需要删除的员工基本信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEmployeesBaseInfoByIds(Long[] ids)
    {
        employeesBaseInfoMapper.deleteEmployeesEducationByEmployeeIds(ids);
        return employeesBaseInfoMapper.deleteEmployeesBaseInfoByIds(ids);
    }

    /**
     * 删除员工基本信息信息
     *
     * @param id 员工基本信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEmployeesBaseInfoById(Long id)
    {
        employeesBaseInfoMapper.deleteEmployeesEducationByEmployeeId(id);
        return employeesBaseInfoMapper.deleteEmployeesBaseInfoById(id);
    }

    @Override
    public List<EmployeesEducationVo> selectEmployeesEducationList(EmployeesBaseInfo employeesBaseInfo) {
        return employeesBaseInfoMapper.selectEducationList(employeesBaseInfo);
    }

    /**
     * 新增员工教育经历信息
     *
     * @param employeesBaseInfo 员工基本信息对象
     */
    public void insertEmployeesEducation(EmployeesBaseInfo employeesBaseInfo)
    {
        List<EmployeesEducation> employeesEducationList = employeesBaseInfo.getEmployeesEducationList();
        Long id = employeesBaseInfo.getId();
        if (StringUtils.isNotNull(employeesEducationList))
        {
            List<EmployeesEducation> list = new ArrayList<EmployeesEducation>();
            for (EmployeesEducation employeesEducation : employeesEducationList)
            {
                employeesEducation.setEmployeeId(id);
                list.add(employeesEducation);
            }
            if (list.size() > 0)
            {
                employeesBaseInfoMapper.batchEmployeesEducation(list);
            }
        }
    }
}
